<?php

define('BME_INSERTION',true);
require_once("../core/Base.php");
require_once(BME_ROOT."core/User.php");
require_once(BME_ROOT."gui/etc.php");

$_Usr = new BME_USER();

switch($_POST['query']){
	case 'create/dataset':
		$BME=new BME_Base();
		$BME->__constructor();
		$BME->openDB();
		foreach($_POST as $k=>$v) ${"p_$k"}=$BME->DBescape($v);
		$BME->DBquery("insert into
			`Dataset`(`idDataset`,`name`,`shortName`,`contact`,`location`,`lat`,`long`,`elevation`,
				`phChProp`,`comments`,`description`)
			values('','$p_name','$p_s_name','$p_who','$p_loc_name','$p_latitude','$p_longitude','$p_elevation',
				'$p_pcp_values','$p_comments','$p_description')");
		$BME->closeDB();
		header("Location: ".BME_SITE."#query/menu/datasets");
	break;
	case 'create/sequences':
		passthru("php '".BME_ROOT."analysis/uploadSequences.php' '".$_FILES['file']['tmp_name']."' '".$_POST['dataset']."' '".$_POST['name']."' 'mute' 2>&1");
		header("Location: ".BME_SITE."#query/menu/sequences");
	break;
	case 'search/sequence':
		// name=>gene, dataset=>dataset, description=>description
		$Bme=new BME_Base();
		$search=rand();
		$fh=fopen($Bme->tmp_path."search/$search","w") or die("I can't write on $search");
		fwrite($fh,serialize($_POST));
		fclose($fh);
		header("Location: ".BME_SITE."#query/menu/search_sequences:$search");
		
	break;
}

?>
